import sqlite3

# 创建一个内存数据库
# 创建一张sales表
# 连接数据库
con = sqlite3.connect(":memory:")
# 创建表sql脚本
query = """CREATE TABLE sales(
 cusomer varchar(20),
 product varchar(40),
 amount float,
 date date);"""
# 执行创建表语句
con.execute(query)
# 提交
con.commit()
# 插入一行测试数据
data = [('Richard Lucas', 'Notepad', 2.50, '2014-01-02'),
        ('Jenny Kim', 'Binder', 4.15, '2014-01-15'),
        ('Svetlana Crow', 'Printer', 155.75, '2014-02-03'),
        ('Stephen Randolph', 'Computer', 679.40, '2014-02-20')]
statement = "Insert into sales values(?,?,?,?)"
con.executemany(statement, data)
con.commit()
# 查询sales表
cursor = con.execute("select * from  sales")
rows = cursor.fetchall()

# 查询总共有多少行
row_count = 0
for row in rows:
    print(row)
    row_count += 1
print("Number of rows:{}".format(row_count))
